package com.dzg.demo.example.singleton;


import com.dzg.demo.annoations.ThreadSafe;
/*  
 * 枚举模式：最安全
 * @author dzg  
 * @date 2018/8/30 22:40
 * @param    
 * @return   
 */ 
@ThreadSafe
public class SingletonExample7 {
    private SingletonExample7() {

    }
    public static SingletonExample7 getInstance(){
        return Singleton.INSTANCE.getSingleton();
    }
    private enum Singleton{
        INSTANCE;
        private SingletonExample7 singleton;
//        JVM保证这个方法绝对只调用一次
        Singleton(){
            singleton=new SingletonExample7();
        }

        public SingletonExample7 getSingleton() {
            return singleton;
        }
    }
}
